package com.jzx.provider.cv.service;

import com.hankcs.hanlp.dictionary.CustomDictionary;
import com.jzx.provider.cv.model.University;
import com.jzx.provider.cv.repository.UniversityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UniversityService {
    @Autowired
    private UniversityRepository universityRepository;

    public void createDir() {
        for (int i = 1; i < 1000; i++) {
            List<University> universities = universityRepository.findByPage((i - 1) * 100, 100);
            if (universities == null || universities.size() == 0) {
                return;
            }
            universities.forEach(university -> {
                CustomDictionary.insert(university.getName(), university.getType() + " " + university.getWeight());
                if (!StringUtils.isEmpty(university.getShortName())) {
                    CustomDictionary.insert(university.getShortName(), university.getType() + " " + university.getWeight());
                }
            });
        }
    }
}
